package com.example.demo.controller;

import com.example.demo.config.BaseUserInfo;
import com.example.demo.pojo.*;
import com.example.demo.service.Impl.UserServiceImpl;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class UserController {
    @Autowired
    private UserServiceImpl userService;
    //管理员列表
    @GetMapping("/admin/list")
    public Result rolesList(@RequestParam(defaultValue = "1") Integer page,
                            @RequestParam(defaultValue = "10") Integer limit,
                            LogTest logTest){
        PageInfo list = userService.rolesList(page,limit,logTest);
        return PageResult.success03(list.getList(), (int) list.getTotal());
    }
    //管理员状态
    @PutMapping("/admin/status")
    public Result rolesStatus(@RequestBody LogTest logTest){
        userService.rolesStatus(logTest);
        return Result.success("解封成功");
    }
    //密码重置
    @PostMapping("/admin/reset")
    public Result userSeset(@RequestBody LogTest logTest){
        userService.userreset(logTest);
        return Result.success("重置成功，默认密码123456");
    }
    //管理员添加
    @PostMapping("/admin/add")
    public Result userAdd(@RequestBody LogTest logTest){
        userService.userAdd(logTest);
        return Result.success("添加成功");
    }
    //管理员删除
    @DeleteMapping("/admin/delete")
    public Result userDelete(LogTest logTest){
        userService.userDelete(logTest);
        return Result.success("删除成功");
    }
    //管理员设置为勾魂使者
    @PutMapping("/admin/reaper")
    public Result userReaper(@RequestBody Enchanter enchanters){
        Enchanter enchanter = userService.userselect(enchanters);
        userService.userReaper(enchanter);
        return Result.success("设置成功");
    }
    //密码修改
    @PutMapping("/admin/password")
    public Result userPassword(@RequestBody LogTest logTest){
        String username = BaseUserInfo.get(UserInfoEnu.username.getCode());
        System.out.println(logTest);
        userService.newPassword(logTest, username);
        return Result.success("修改成功");
    }

    //昵称修改
    @PutMapping("/admin/nickname")
    public Result userNickname(@RequestBody LogTest logTest){
        String username = BaseUserInfo.get(UserInfoEnu.username.getCode());
        String password = BaseUserInfo.get(UserInfoEnu.password.getCode());
        userService.newNickname(logTest, username,password);
        return Result.success("修改成功");
    }
    //管理员角色设置
    @PostMapping("/role/admin")
    public Result newuserRole(@RequestBody LogTest logTest){
        userService.newuserRole(logTest);
        return Result.success("修改成功");
    }



}
